<script>
    $("#security_code").click(function () {
        var phone = $('#phone').val()
        if (phone.length != 11 || (phone.substring(0, 1) != 1)) {
            alert('请检查手机号码')
            return
        }
        var code = $("#security_code");
        code.attr('disabled', true)
        var time = 59;
        $.ajax({
            type: "POST",
            url: sendSmsUrl,
            timeout: 20000,
            data: {request: JSON.stringify({data: {phone: phone}})},
            dataTpye: 'json',
            success: function (msg) {
                if (!msg.response.success) {
                    alert(msg.response.message)
                }
            },
            error: function () {
                alert('发送失败')
            }
        })

        var interval = setInterval(function () {
            code.text("获取验证码(" + time + ")")
            if (time == 0) {
                code.text("重新发送")
                code.removeAttr('disabled')
                clearInterval(interval)
            }
            --time;
        }, 1000)
    });


    function login() {
        var phone = $('#phone').val()
        var code = $('#code').val()
        var pwd = $('#pwd').val()
        if (!phone || phone.length != 11 || (phone.substring(0, 1) != 1)) {
            alert('请检查手机号码')
            return
        }
        if (!code || code.length != 6) {
            alert('请输入验证码')
            return
        }
        if (!pwd || pwd.length < 4) {
            alert('请检查密码')
            return
        }
        var form = $('#form');
        var params = {
            data: {
                phone: phone,
                verificationCode: code,
                password: pwd
            }
        };
        form.append("<input type='hidden' value='" + JSON.stringify(params) + "' name='request'>");
        form.submit();
    }

    function updatePassword() {
        var phone = $('#phone').val()
        var code = $('#code').val()
        var pwd = $('#pwd').val()
        var pwds = $('#pwds').val()
        if (!phone || phone.length != 11) {
            alert('请检查手机号码')
            return
        }
        if (!code || code.length != 6) {
            alert('请输入验证码')
            return
        }
        if (!pwd || pwd.length < 4) {
            alert('请检查密码')
            return
        }
        if (pwd != pwds) {
            alert('您输入的密码两次不一致')
            return
        }
        var form = $('#form');
        var params = {
            data: {
                phone: phone,
                verificationCode: code,
                password: pwd,
                confirmPassword: pwd
            }
        };
        form.append("<input type='hidden' value='" + JSON.stringify(params) + "' name='request'>");
        form.submit();
    }

</script>